<?php
/**
 * Created by PhpStorm.
 * User: TianFeng
 * Date: 2017/12/27
 * Time: 16:11
 */
namespace app\merchant\sercive;
use app\common\lib\Page;
use app\merchant\controller\Common;
use think\console\command\make\Controller;
use think\Db;
use think\config;
class Enterpriseloansercive extends  Controller {
  //企业借款人列表
    function _initialize()
    {
        parent::_initialize(); //
    }

    public function index($array)
   {

   }
   //企业借款人信息
    public function show($array)
    {

    }
    //修改企业借款人信息
    public function update($array)
    {

    }
    //添加企业借款人

    public function add($array,$image)
    {
        Db::startTrans();
        try{
            //企业信息填入;
           $InsertId = db('user_company')->insertGetId($array);
            //创建此企业的文件夹  单独存放此企业信息文件  每天一个文件夹
            $file_name = date('y-m-d').'\\'.$InsertId;
            //文件上传目录 配置
            $Path = require(APP_COMMON . 'conf/file_path.php');
            $url =  ROOT_PATH . $Path['company_file_path'].$file_name;
            $image_file_path =   ROOT_PATH . $Path['upload_path'];
            //创建商户自己的图片文件夹
            if(!create_file($url))
            {
                return  '文件创建失败,请重新添加';
            }
            $Config = require(MERCHANT_CONF . 'conf/config.php');
            foreach ($image as $key=>$value)
            {
                if(!empty($value)){
                    $image_path = explode('/',$value);
                    if(!copy($image_file_path.end($image_path),iconv("UTF-8", "GBK",$url.'\\'.$Config['company_image'][$key]))){
                        Db::rollback();
                        echo  '文件操作失败';
                    }
                    unlink($image_file_path.end($image_path));
                }
            }
            Db::commit();
        }catch(\Exception $exception)
        {
            Db::rollback();
            return $exception;
        }
        return $InsertId;
    }



}
